<template>
  <div class="onekit-checkbox-group"
       :class="onekitClass"
       :style="onekitStyle"
       :id="onekitId">
    <slot></slot>
  </div>
</template>

<script>
import weixin_behavior from "../../behaviors/weixin_behavior"
import onekit_behavior from "../../behaviors/onekit_behavior"
import eventBus from '../../api/EventBus'
export default {
  name: "onekit-checkbox-group",
  mixins: [weixin_behavior, onekit_behavior],
  data () {
    return {
      chckboxArr: []
    }
  },
  model: {
    prop: "value",
    event: "select"
  },
  watch: {
 /*   value (newValue) {
      this.$emit("Change", newValue);
    },*/
    chckboxArr: {
      deep: true,
      handler (v) {
        const changeData = {
          currentTarget: {
            id: '',
            offsetLeft: 0,
            offsetTop: 0,
            dataset: {}
          },
          detail: {
            value: v
          },
          mark: {},
          mut: false,
          target: {
            id: '',
            offsetLeft: 0,
            offsetTop: 0,
            dataset: {}
          },
          timeStamp: new Date().getTime(),
          type: 'change',
          _usertap: true
        }
        this.$emit('Change', changeData)
      }
    }
  },
  methods: {
    // selectItem(item) {
    //   const { value } = this;
    //   this.$emit("select", [...value, item]);
    //   console.log([...value, item])
    // },
    // deleteItem(item) {
    //   const { value: selectItems } = this;
    //   this.$emit(
    //     "select",
    //     selectItems.filter(selectitem => selectitem !== item)
    //   );
    // }
  },
  mounted () {
    eventBus.$on('onekit-foem-item-reset', () => {
      this.chckboxArr.length = 0
    })
    eventBus.$on('checkBox-val-confirm', data => {
      this.chckboxArr.push(data)
      eventBus.$emit('onekit-checkbox-submit', this.chckboxArr)
    })
    eventBus.$on('checkBox-val-cancel', data => {
      const index = this.chckboxArr.indexOf(data)
      this.chckboxArr.splice(index, 1)
      eventBus.$emit('onekit-checkbox-submit', this.chckboxArr)
    })

  }
}
</script>

<style scoped>
</style>
